package erp.server.organization.controller;

import erp.server.base.response.JsonResult;
import erp.server.organization.pojo.dto.OrganizationAddParam;
import erp.server.organization.pojo.dto.OrganizationQueryParam;
import erp.server.organization.pojo.vo.OrganizationVO;
import erp.server.organization.service.OrganizationService;
import erp.server.role.pojo.dto.RoleAddParam;
import erp.server.role.service.RoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Api(tags = "组织模块")
@Slf4j
@RestController
@RequestMapping("/isms/organization/")
public class OrganizationController {

    @Autowired
    private OrganizationService organizationService;

    @Autowired
    private RoleService roleService;

    //创建组织和修改组织
    @ApiOperation("创建组织")
    @PostMapping("add")
    public JsonResult addOrganization(OrganizationAddParam organizationAddParam) {
        log.debug("organizationAddParam-controller:{}",organizationAddParam);
        organizationService.addOrganization(organizationAddParam);
        return JsonResult.ok();
    }

    @ApiOperation("查询组织")
    @GetMapping("select")
    public JsonResult select(OrganizationQueryParam organizationQueryParam){
        log.debug("organizationQueryParam-controller:{}",organizationQueryParam);
        List<OrganizationVO> organizationList = organizationService.select(organizationQueryParam);
        return JsonResult.ok(organizationList);
    }

    @ApiOperation("删除组织")
    @PostMapping("delete/{id}")
    public JsonResult delete(@PathVariable("id") Integer id){
        log.debug("id-controller:{}", id);
        //删除组织的信息
        organizationService.delete(id);
        //删除role表中的信息
        roleService.delete(id);
        return JsonResult.ok();
    }


    @ApiOperation("加入组织")
    @PostMapping("join")
    public JsonResult addRole(RoleAddParam roleAddParam) {
        log.debug("roleAddParam-controller: {}", roleAddParam);
        roleService.insert(roleAddParam);
        return JsonResult.ok();
    }



}
